from django.db import models
from django.contrib import admin
from gaevents.models import Gaevent, Gabusiness
import datetime
import time

class Gauser(models.Model):

    GENDER_CHOICES = (
      ('M', 'Male'),
      ('F', 'Female'),
      ('U', 'Undecided')
    )

    YESNO_CHOICES = (
      (0, 'No'),
      (1, 'Yes')
    )

    id = models.AutoField(primary_key=True)
    firstname = models.CharField("First Name",max_length=75)
    lastname = models.CharField("Last Name", max_length=75)
    email = models.CharField(max_length=150)
    currentzip = models.CharField(max_length=30)
    gender = models.CharField(max_length=1, choices=GENDER_CHOICES)
    birthday = models.DateField()
    password_2 = models.CharField(max_length=120)
    salt = models.CharField(max_length=96)
    is_active = models.IntegerField() #probably confirmation email thing
    is_public = models.IntegerField("Public?",choices=YESNO_CHOICES)
    class Meta:
        db_table = u'gauser'

    def __str__(self):
      return self.email

    def get_business_list(self):
      user = Gauser.objects.get(email = self.email)
      fetchlist = []
      try:
        fetchlist = Gauseraddedbusiness.objects.get(id = user.id)
      except:
        print user.email, " has no businesses favorited"
      businesslist = fetchlist
      return businesslist

    def save(self):
      self.is_active = 1
      self.password_2 = 'feline'
      self.salt = 's3dq4saswd2'
      super(Gauser, self).save() 

class Gauserfriend(models.Model):
    gauser = models.ForeignKey(Gauser)
    friend = models.ForeignKey(Gauser, related_name='friend')
    class Meta:
        db_table = u'gauserfriend'

class Gauseraddedevent(models.Model):
    id = models.AutoField(primary_key = True)
    gauser = models.ForeignKey(Gauser)
    #gaevents_gasubcategory_idgasubcategory = models.IntegerField()
    #gaevents_gasubcategory_gamaincategory_idgamaincategory = models.IntegerField()
    gaevent = models.ForeignKey(Gaevent)
    is_public = models.IntegerField()
    class Meta:
        db_table = u'gauseraddedevent'

class Gauseraddedbusiness(models.Model):
    id = models.AutoField(primary_key= True)
    gauser = models.ForeignKey(Gauser)
    gabusiness  = models.ForeignKey(Gabusiness)
    class Meta:
        db_table = u'gauseraddedbusiness'
    #returns a tuple? need to format it

   
class Gauserzip(models.Model):
    id = models.AutoField(primary_key=True)
    gauser = models.ForeignKey(Gauser)
    zip = models.CharField(max_length=10)
    class Meta:
        db_table = u'gauserzip'



"""

class GauserAdmin(admin.ModelAdmin):

  list_display = ('email',)
  fieldsets = [
    (None,                      {'fields': [('firstname', 'lastname'), 'email']}),
    ('Additional Information',          {'fields': ['birthday', 'gender', 'currentzip', 'is_public']})


  ]
"""

